package cn.com.jit.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import cn.com.jit.dao.UserDao;
import cn.com.jit.vo.User;

@Repository("userDao")
public class UserDaoImpl extends SqlSessionDaoSupport implements UserDao{

	private SqlSessionFactory sqlSessionFactory;
	@Autowired
	@Override
	public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
		super.setSqlSessionFactory(sqlSessionFactory);
	}
	
	@Override
	public List<User> list() {
		// TODO Auto-generated method stub
		return getSqlSession().selectList("cn.com.jit.vo.list");
	}

	@Override
	public int add(User user) {
		// TODO Auto-generated method stub
		return getSqlSession().insert("cn.com.jit.vo.add", user);
		//return 0;
	}

	@Override
	public int delete(String id) {
		// TODO Auto-generated method stub
		return getSqlSession().delete("cn.com.jit.vo.delete", id);
		//return 0;
	}

	@Override
	public User findUserById(String id) {
		// TODO Auto-generated method stub
		List<User> users = getSqlSession().selectList("cn.com.jit.vo.selectbyid", id);
		return users.get(0);
		//return null;
	}

	@Override
	public int updateUser(User user) {
		// TODO Auto-generated method stub
		return getSqlSession().update("cn.com.jit.vo.updateuser", user);
		//return 0;
	}

}
